#pragma once
#include "DXAMLCommon.h"


class CRasterizerPath;
class CMILMatrix;
class CPathBlock;
class CPathGeometry;
class CPathFigureCollection;
class CPathFigure;


class CGeometryBuilder
{
public: 
	CGeometryBuilder(CCoreServices * pCoreServices);
	~CGeometryBuilder();
	HRESULT OpenGeometry();
	HRESULT OpenFigure(XINT32 flags, struct XPOINTF * ppt);
	HRESULT SetFigureFilled(XBOOL bFill);
	HRESULT CloseFigure();
	HRESULT ComputeReflection(XINT32 flags, enum PathPointType type, struct XPOINTF * ppt);
	HRESULT AddLine(XINT32 flags, struct XPOINTF * ppt);
	HRESULT AddBezier(XINT32 flags, struct XPOINTF * ppt);
	HRESULT AddQuadratic(XINT32 flags, struct XPOINTF * ppt);
	HRESULT AddArc(XINT32 flags, struct XPOINTF * ppt, XFLOAT eAngle, XINT32 bLarge, XINT32 bClockwise, const CMILMatrix * pMatrix);
	HRESULT AddSegments(enum PathPointType type, XUINT32 cPoint, struct XPOINTF * pPoint);
	HRESULT ReplaceLastPoint(struct XPOINTF * ppt);
	HRESULT CloseGeometry(CRasterizerPath * pRasterizerPath);
	static HRESULT DrawEllipse(CRasterizerPath * * ppRasterizerPath, const struct XPOINTF & ptCenter, const XFLOAT & inputRadiusX, const XFLOAT & inputRadiusY);
	static HRESULT DrawRectangle(CRasterizerPath * * ppRasterizerPath, const struct XRECTF_WH & rc, const XFLOAT & inputRadiusX, const XFLOAT & inputRadiusY);
	static void CalculateRoundedCornersRectangle(struct XPOINTF * pCorners, const struct XRECTF_WH & rc, const struct XRECTF_CR & rCornerRadius, const struct XRECTF_RB * pBorders, XBOOL fOuter);
	static HRESULT DrawRoundedCornersRectangle(struct IPALGeometrySink * ppRasterizerPath, const struct XRECTF_WH & rc, const struct XRECTF_CR & rCornerRadius, const struct XRECTF_RB * pBorders, XBOOL fOuter);
	static HRESULT DrawRoundedCornersRectangle(struct IPALAcceleratedGeometry * * ppPALGeometry, struct IPALAcceleratedGraphicsFactory * pD2DFactory, const struct XRECTF_WH & rc, const struct XRECTF_CR & rCornerRadius, const struct XRECTF_RB * pBorders, XBOOL fOuter);
	static HRESULT DrawRoundedCornersRectangle(CRasterizerPath * * ppRasterizerPath, const struct XRECTF_WH & rc, const struct XRECTF_CR & rCornerRadius, const struct XRECTF_RB * pBorders, XBOOL fOuter);
	static HRESULT DrawLines(CRasterizerPath * * ppRasterizerPath, XUINT32 cPoints, const struct XPOINTF * pPoints, XBOOL fClosed);
	static HRESULT DrawMultipleLines(struct IPALAcceleratedGeometry * *, struct IPALAcceleratedGraphicsFactory *, XUINT32, const struct XPOINTF *);
	static HRESULT DrawMultipleLines(CRasterizerPath * *, XUINT32, const struct XPOINTF *, XUINT32);
	static HRESULT AddPoints(struct IPALAcceleratedPathGeometry * pPALGeometry, struct XPOINTF * pPoints, XUINT32 cPoints, XUINT8 * pTypes, enum XcpFillMode fillMode);
protected: 
	static HRESULT EnsureRasterizerPath(CRasterizerPath * * ppRasterizerPath, XUINT32 cPoints);
	XINT32 VerifyFlag(XINT32 x, XINT32 flag);
	void MakeAbsolute(XINT32 flags, XUINT32 cpt, struct XPOINTF * ppt);
	HRESULT StorePoints(enum PathPointType type, XUINT32 cPoint);
private: 
	CPathBlock * m_pHead;
	CPathBlock * m_pCurr;
	XUINT32 m_cPoint;
	struct XPOINTF m_ptStart;
	struct XPOINTF m_aAbsolute[3];
	struct XPOINTF * m_pAbsolute;
	struct XPOINTF * m_pptCurr;
	struct XPOINTF * m_pptReflect;
	struct XPOINTF m_ptLastMove;
	XUINT32 m_typePrev;
	XBOOL m_bValid;
	XBOOL m_bOpen;
	XBOOL m_bPendingMove;
	XUINT8 m_fTypeFlags;
public: 
	HRESULT OpenPathGeometryBuilder();
public: 
	HRESULT ClosePathGeometryBuilder(CPathGeometry * pPathGeometry);
	XBOOL IsBuildingFigure();
	CCoreServices * m_pCoreNoRef;
	CPathFigureCollection * m_pPathFigures;
	CPathFigure * m_pCurrentPathFigure;
	struct XPOINTF m_ptCurr;
	struct XPOINTF m_ptReflect;
};
